/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.core.language;

import java.util.HashSet;
import java.util.Set;

public class USKeywords {

    private static USKeywords selfInstance = null;

    public static USKeywords instance() {
        synchronized (USKeywords.class) {
            if (selfInstance == null) {
                selfInstance = new USKeywords();
                selfInstance.initialize();
            }
        }
        return selfInstance;
    }

    private USKeywords() {
    }

    // TODO rework
    public static final String[] KW = { "native", "nativereplication", "dependson", "abstract", "deprecated",
            "transient", "nontransient", "config", "perobjectconfig", "perobjectlocalized", "editinlinenew",
            "editconst", "noteditinlinenew", "placeable", "notplaceable", "hidedropDown", "hidecategories",
            "showcategories", "autoexpandcategories", "collapsecategories", "dontcollapsecategories", "within",
            "inherits", "implements", "noexport", "class", "interface", "struct", "structdefaultproperties", "cpptext",
            "structcpptext", "defaultproperties", "enum", "function", "operator", "event", "var", "if", "else", "do",
            "for", "while", "foreach", "exec", "return", "break", "switch", "until", "new", "case", "default",
            "extends", "void", "float", "double", "bool", "string", "name", "int", "coerce", "byte", "array", "simulated",
            "state", "true", "false", "local", "super", "static", "final", "const", "private", "immutable", "out",
            "optional", "delegate", "localized", "editoronly", "noimport", "globalconfig", "replication", "repnotify", "protected",
            "reliable", "unreliable", "server", "client", "export" };

    public static final String[] OPERATORS = { "+", "-", "dot", "$" };

    private final Set<String> keywords = new HashSet<String>();

    public void initialize() {
        for (int i = 0; i < KW.length; i++) {
            if (keywords.contains(KW[i])) {
                System.out.println("DUPLICATE " + KW[i]);
            }
            keywords.add(KW[i]);
        }
    }

    public Set<String> getAllKeywords() {
        return keywords;
    }

    public Set<String> getStartsWith(String prefix) {
        Set<String> result = new HashSet<String>();
        for (String keyword : keywords) {
            if (keyword.startsWith(prefix)) {
                result.add(keyword);
            }
        }
        return result;
    }

}
